<?php
/**
 * Asset Model - Attaches itself with a Model to support upload of multiple files
 * Asset can be refered to any image / video or any media file type. Any model requiring more than one file can use Asset Model
 * i.e Cafe hasMany Asset will allow uploading of any number of media for a particular cafe_id
 * Drawbacks: Allowed file types can not be specified as per model. Suppose a Cafe is needing only 'Image' type assets, while 'Reviews' require both 'Videos' and 'Image' type assets. 
 * Need to allow that using Configuration of plugin.
 *
 */


 class Asset extends AppModel
{
	var $name = "Asset";
	/**
	 * This will store instance of model for which present Asset model is being
	 * used.eg Object of Recipe model when RecipeAsset belongs to Recipe.
	 * @var unknown_type
	 */
	var $dependentModel = null;
	var $fieldProperties = array(
		"name" => array('type'=>"file","label"=>"File","group"=>"add"),
	);
	const PUBLISHED = 1;
	const SPAM = 2;
	function initialize()
	{
		if(!isset($this->actsAs['Upload']))
		{
			/*$this->actsAs['Upload'] = array(
			'field' => 'name',
			"allowedMedia"=>array("Image","Video","Text"),
			'empty'	=>false,
			);*/
		}
		parent::initialize();
	}
	/**
	 * Return model name with present model have relation of belongsTo and for which it is being used
	 * @return unknown_type
	 */
	function getDependentModel()
	{
		if(empty($this->dependentModel) || is_object($this->dependentModel)==false)
		{
			$modelNameParts = explode("_",Inflector::underscore($this->name));
			array_pop($modelNameParts);
			
			$modelName = Inflector::camelize(implode("_",$modelNameParts));
			$this->dependentModel = $this->{$modelName};
		}
		return $this->dependentModel;
	}
	
}
?>